<?php
/**
 * System_Model_DbTable_Menu
 *
 * @author mmxie
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: Menu.php 1082 2011-12-09 09:27:48Z mmxie $
 */
class System_Model_DbTable_Menu extends IG_Model_DbTable
{
    protected $_name = 'sys_tree';

    protected $_primary = 'id';

    public function getByParentId($parentId)
    {
        $roles = array();
        foreach (Zend_Auth::getInstance()->getIdentity()->getRoles() as $role) {
            $roles[] = $role->getRoleId();
        }
        return $this->select()->setIntegrityCheck(false)
                    ->from($this->_name, array('id', 'title', 'parent_id', 'url', 'type', 'iframe'))
                    ->distinct()
                    ->joinLeft('sys_role_resource', 'resource_id=permission', null)
                    ->where('(role_id in (?)', $roles)
                    ->orWhere('permission=0)')
                    //->where('top_parent_id=?', $parentId)
                    ->order('position')
                    ->query()
                    ->fetchAll();
    }
}